package cn.broadmax.boot.util;

import cn.broadmax.boot.base.model.LoginUser;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * spring常用工具
 * @author jeff
 * @date 2020/6/20
 */
public abstract class SpringContextUtils {

    public static HttpServletRequest getHttpServletRequest() {
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        if(!(requestAttributes instanceof ServletRequestAttributes)){
            return null;
        }
        return ((ServletRequestAttributes) requestAttributes).getRequest();
    }

    public static LoginUser getSubject(){
        return ThreadLocalContext.getSubject();
    }

}
